package com.tyg.service.impl;

import com.tyg.entity.ExercisesInfo;
import com.tyg.mapper.ExercisesInfoMapper;
import com.tyg.service.ExercisesInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhangjingnan
 * @since 2022-11-05
 */
@Service
public class ExercisesInfoServiceImpl extends ServiceImpl<ExercisesInfoMapper, ExercisesInfo> implements ExercisesInfoService {

    @Autowired
    ExercisesInfoMapper exercisesInfoMapper;

    @Override
    public List<ExercisesInfo> getExerciseList() {
        return exercisesInfoMapper.getExerciseList();
    }

    @Override
    public ExercisesInfo selectById(Integer exercisesId) {
        return exercisesInfoMapper.selectById(exercisesId);
    }

    @Override
    public List<ExercisesInfo> getExercise(Map<String, Object> map) {
        return exercisesInfoMapper.getExercise(map);
    }

    @Override
    public int insert(ExercisesInfo exercisesInfo) {
        return exercisesInfoMapper.insert(exercisesInfo);
    }

    @Override
    public boolean updateById(ExercisesInfo exercisesInfo) {
        int upd=exercisesInfoMapper.updateById(exercisesInfo);
        if(upd==0){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public int updateByOld( ExercisesInfo exercisesInfo) {
        Integer idOld=exercisesInfo.getExercisesId();
        ExercisesInfo exercisesInfo1=exercisesInfoMapper.selectById(idOld);
        exercisesInfo.setPhoto(exercisesInfo1.getPhoto());
        exercisesInfo.setStatus(1);
        int updNew=exercisesInfoMapper.updateById(exercisesInfo);
        return updNew;
    }

    @Override
    public ExercisesInfo retract(Integer exercisesId) {
        ExercisesInfo exercisesInfo=exercisesInfoMapper.selectById(exercisesId);
        exercisesInfo.setStatus(2);
        int result=exercisesInfoMapper.updateById(exercisesInfo);
        ExercisesInfo exercisesInfo1=exercisesInfoMapper.selectById(exercisesId);
        return exercisesInfo1;
    }


}